import java.util.Arrays;

public class QuickSort {
    public static void main(String[] args) {
        int[] nums = {6, 5, 4, 3, 2, 1, 0};
        sort(nums);
        System.out.println(Arrays.toString(nums));
    }

    public static void sort(int[] nums) {
        sort(nums, 0, nums.length - 1);
    }

    public static void sort(int[] nums, int l, int h) {
        if (l >= h) return;
        int i = l, j = h + 1;
        while (true) {
            while (nums[++i] < nums[l] && i != h) ;
            while (nums[--j] > nums[l] && j != l) ;
            if (i >= j)
                break;
            swap(nums, i, j);
        }
        swap(nums, l, j);
        sort(nums, l, j - 1);
        sort(nums, j + 1, h);
    }


    private static void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}
